package demo2;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Test {
    //花色固定，所以用static final 修饰
    public static final String SUITS[] = {"♥", "♣", "♦", "♠"};

    //写一个方法生成牌
    public static List<Card> buyCard() {
        List<Card> cards = new ArrayList<>();
        for (int j = 0; j < SUITS.length; j++) {
            for (int i = 1; i < 14; i++) {
                Card card = new Card(SUITS[j], i);
                cards.add(card);
            }
        }
        return cards;
    }
    public static void shufle(List<Card> cards){
        Random random = new Random();
        for (int i = 1; i < cards.size() - 1; i++) {
            int j = random.nextInt(i);
            Card tmp = cards.get(j);
            cards.set(j,cards.get(i));
            cards.set(i,tmp);
        }
    }
        public static void main (String[]args){
        List<Card> card = buyCard();
            System.out.println(card);
            System.out.println("洗牌:");
            shufle(card);
            System.out.println(card);
            System.out.println("揭牌");
            List<Card> hand1 = new ArrayList<>();
            List<Card> hand2 = new ArrayList<>();
            List<Card> hand3 = new ArrayList<>();
            List<List<Card>> hand = new ArrayList<>();
            hand.add(hand1);
            hand.add(hand2);
            hand.add(hand3);
            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < 3; j++) {
                    card.remove(0);
                    hand.get(j).add(card.remove(0));
                }
            }
            System.out.println("第一个人的牌");
            System.out.println(hand1);
            System.out.println("第二个人的牌");
            System.out.println(hand2);
            System.out.println("第三个人的牌");
            System.out.println(hand3);
            System.out.println("剩下的牌：");
            System.out.println(hand);


        }
    }

